#!/bin/bash
set -e

# Check if the CUDA test exists
if [ ! -f build/test_cuda ]; then
  echo "CUDA test not found. Building the project with CUDA support..."
  ./build.sh --cuda --test
fi

# Run the CUDA test and capture output
echo "Running CUDA test..."
build/test_cuda > cuda_test.log

# Check if compare_norm.py is available
if command -v compare_norm.py &> /dev/null; then
  COMPARE_CMD="compare_norm.py"
elif [ -f build/compare_norm.py ]; then
  COMPARE_CMD="python build/compare_norm.py"
elif [ -f compare-diff/compare_norm.py ]; then
  COMPARE_CMD="python compare-diff/compare_norm.py"
else
  echo "Error: compare_norm.py not found"
  exit 1
fi

# Compare the norms
echo "Comparing CPU vs GPU norms..."
cat cuda_test.log | $COMPARE_CMD

echo "Comparison complete. Results saved in cuda_test.log" 